// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
/* jshint esversion: 6 */
window.getIps = "//api.mofing.com";
window.getIpwwws = "//www.mofing.com";

import Vue from 'vue';
import App from './App';
import router from './router';
import axios from 'axios';
import qs from 'qs';

Vue.filter("filterTimes", function (val) {
  let y = new Date(val).getFullYear();
  let m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
  let d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
  return y + "-" + m + "-" + d;
});
Vue.filter("filterTimesss", function (val) {
  let y = new Date(val).getFullYear();
  let m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
  let d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
  let h = new Date(val).getHours() >= 10 ? new Date(val).getHours() : '0' + new Date(val).getHours();
  let ms = new Date(val).getMinutes() >= 10 ? new Date(val).getMinutes() : '0' + new Date(val).getMinutes();
  return y + "-" + m + "-" + d + " " + h + ":" + ms;
});

function axiosPost(url, params, bool) {
  return new Promise((resolve, reject) => {
    axios({
      url: bool === true ? window.getIpwwws + url : window.getIps + url,
      method: 'post',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
      },
      data: qs.stringify(params)
    }).then(res => {
      resolve(res.data);
    }).catch((error) => {
      reject(error);
    });
  });
}

function axiosGet(url, params, bool) {
  return new Promise((resolve, reject) => {
    axios({
      url: bool === true ? window.getIpwwws + url : window.getIps + url,
      method: 'get',
      timeout: 25000,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
      },
      params
    }).then(res => {
      resolve(res.data);
    }).catch((error) => {
      reject(error);
    });
  });
}

Vue.config.productionTip = false;

Vue.prototype.$axiosPost = axiosPost; //全局axiosPost配置----------交互就用这个足够
Vue.prototype.$axiosGet = axiosGet; //全局axiosGet配置

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'
});
